package com.ihr360.payroll.model.dto.staff;

import com.ihr360.alps.api.ServiceProvider;
import com.ihr360.expr.parser.ExprToken;
import com.ihr360.payroll.model.dto.salary.basecode.SalaryFieldType;
import com.ihr360.shared.entitywithlistener.NumberIdWithTimeAndCompanyId;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

@Entity
@Table(uniqueConstraints = @UniqueConstraint(columnNames = {"companyId", "code"}))
public class SalaryProfileField extends NumberIdWithTimeAndCompanyId<Long> {

    @Column(nullable = true, length = 32, updatable = false)
    //预留序列号生成器，为工资添加自定义薪资项目做准备，暂时注释
    //@CodeGenerator(bizModel = "salary_profile_field",serialTmpl = "SERIALGEN(\"C_S_P_F_\",MAXID)",isForCompany=true,name = "薪资档案序列号")
    private String code;

    /**
     * 序号
     */
    protected int indexno = 1;

    /**
     * 薪资项目类别
     */
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(nullable = false)
    protected SalaryFieldType type;

    @Transient
    private String name;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public int getIndexno() {
        return indexno;
    }

    public void setIndexno(int indexno) {
        this.indexno = indexno;
    }

    public SalaryFieldType getType() {
        return type;
    }

    public void setType(SalaryFieldType type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    /**
     * 作为公司薪资字段时对应工资表中公式的引用公式
     *
     * @return
     */
    public String getCompanySalaryReferenceFormula() {
        return String.join("", ExprToken.EQUAL.val, ServiceProvider.SERVICE_ID.STAFF_SALARY, ExprToken.NS_FIELD_CONNECTOR.val, code);
    }


}